function s = analytichandle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% int Z_t^2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% project on 1, mean part
s.sqmean0 = @sqmean0;
% project on xi
s.sqxi1 = @sqxi1;
s.sqonxik = @sqonxik;
% project on xi square
s.sq1 = @sq1;
s.sqonxisq = @sqonxisq;
% project on xi_ixi_j, mixed part
s.sqmix1k = @sqmix1k;
s.sqmixij = @sqmixij;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% int Z_t
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% project on 1, mean part
s.mean0 = @mean0;
% project on xi
s.xi1 = @xi1;
s.xik = @xik;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Z_t

s.meanzt = @meanzt;
s.ztxi1 = @ztxi1;
s.ztxik = @ztxik;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y = Ak(k,T)
y = sqrt(2/T)/(1+((k-1)*pi/T)^2);
end
function y = Bk(k,T)
y = (k-1)*pi/T;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y = sqmean0(t,T)   % checked
y = 3/2*(T-t)+1/4*exp(-2*T)-1/4*exp(-2*t);
end
function y = sqxi1(t,T)   % checked
y = 2*(1/sqrt(T)*(T-t+exp(-T)-exp(-t)));
end
function y = sqonxik(k,t,T) % checked
y = 2*(Ak(k,T)*(-1/Bk(k,T)*sin(Bk(k,T)*t)+exp(-T)-exp(-t)-(-1)^(k-1)+cos(Bk(k,T)*t)));
end
function y = sqmix1k(k,t,T) % checked
y = 2*((Ak(k,T)*(2/exp(T) - 1/exp(2*T) - 2./exp(t) + 1./exp(2*t) ...
    - 2*cos(Bk(k,T)*T) + 2*cos(Bk(k,T)*t) - (2*cos(Bk(k,T)*t))./exp(t) ...
    + (2*cos(Bk(k,T)*T))/exp(T)))/(2*T^(1/2)) + (Ak(k,T)*(2*sin(Bk(k,T)*T) ...
    - 2*sin(Bk(k,T)*t)))/(2*Bk(k,T)*T^(1/2)));
end
function y = sqmixij(i,j,t,T)   % checked

y = 2*(-(Ak(i,T)*Ak(j,T)*(Bk(i,T)^2/exp(2*T) - Bk(j,T)^2/exp(2*T) ...
    - Bk(i,T)^2./exp(2*t) + Bk(j,T)^2./exp(2*t) ...
    + Bk(i,T)^2*(2*cos(Bk(i,T)*T)*cos(Bk(j,T)*T) ...
    - 2*cos(Bk(i,T)*t).*cos(Bk(j,T)*t)) + (Bk(i,T)^2*(2*cos(Bk(i,T)*t) ...
    + 2*cos(Bk(j,T)*t)))./exp(t) - (Bk(j,T)^2*(2*cos(Bk(i,T)*t) ...
    + 2*cos(Bk(j,T)*t)))./exp(t) - 2*Bk(j,T)^2*cos(Bk(i,T)*T)*cos(Bk(j,T)*T) ...
    - (Bk(i,T)^2*(2*cos(Bk(i,T)*T) + 2*cos(Bk(j,T)*T)))/exp(T) ...
    + (Bk(j,T)^2*(2*cos(Bk(i,T)*T) + 2*cos(Bk(j,T)*T)))/exp(T) ...
    + 2*Bk(j,T)^2*cos(Bk(i,T)*t).*cos(Bk(j,T)*t) ...
    + 4*Bk(i,T)*Bk(j,T)*cosh(log(Bk(i,T)))*cos(Bk(i,T)*T)*sin(Bk(j,T)*T) ...
    - 4*Bk(i,T)*Bk(j,T)*cosh(log(Bk(j,T)))*cos(Bk(j,T)*T)*sin(Bk(i,T)*T) ...
    - 4*Bk(i,T)*Bk(j,T)*cosh(log(Bk(i,T)))*cos(Bk(i,T)*t).*sin(Bk(j,T)*t) ...
    + 4*Bk(i,T)*Bk(j,T)*cosh(log(Bk(j,T)))*cos(Bk(j,T)*t).*sin(Bk(i,T)*t)))/(2*(Bk(i,T)^2 ...
    - Bk(j,T)^2)));
end
    function y = sq1(t,T) % checked
y = sqrt(2)*(1 - (t - 2/exp(T) + 1/(2*exp(2*T)) + 2./exp(t) - 1./(2*exp(2*t)))/T);
end
function y = sqonxisq(k,t,T) % checked

y = sqrt(2)*(-Ak(k,T)^2*(1/(2*exp(2*T)) - 1./(2*exp(2*t)) + cos(2*Bk(k,T)*T)/2 ...
    - cos(2*Bk(k,T)*t)/2 + (2*cos(Bk(k,T)*t))./exp(t) - T*(Bk(k,T)^2/2 + 1/2) ...
    + t*(Bk(k,T)^2/2 + 1/2) - (2*cos(Bk(k,T)*T))/exp(T) ...
    + (sin(2*Bk(k,T)*T)*(Bk(k,T)^2 - 1))/(4*Bk(k,T)) ...
    - (sin(2*Bk(k,T)*t)*(Bk(k,T)^2 - 1))/(4*Bk(k,T))));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y = mean0(t,T)
y = T-t;
end
function y = xi1(t,T)
y = sqrt(2)*(1 - (t - 2/exp(T) + 1/(2*exp(2*T)) + 2./exp(t) - 1./(2*exp(2*t)))/T);
end
function y = xik(k,t,T)
y = sqrt(2)*(-Ak(k,T)^2*(1/(2*exp(2*T)) - 1./(2*exp(2*t)) + cos(2*Bk(k,T)*T)/2 ...
    - cos(2*Bk(k,T)*t)/2 + (2*cos(Bk(k,T)*t))./exp(t) - T*(Bk(k,T)^2/2 + 1/2) ...
    + t*(Bk(k,T)^2/2 + 1/2) - (2*cos(Bk(k,T)*T))/exp(T) ...
    + (sin(2*Bk(k,T)*T)*(Bk(k,T)^2 - 1))/(4*Bk(k,T)) ...
    - (sin(2*Bk(k,T)*t)*(Bk(k,T)^2 - 1))/(4*Bk(k,T))));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y = meanzt(~)
y = 1;
end
function y = ztxi1(t,T)
y = 1/sqrt(T)*(1-exp(-t));
end
function y = ztxik(k,t,T)
y = Ak(k,T)*(cos(Bk(k,T)*t)-exp(-t)+Bk(k,T)*sin(Bk(k,T)*t));
end
   


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%